package com.gitee.feizns.convert;

import java.util.HashMap;
import java.util.Map;

/**
 * @author feizns
 * @since 2019/5/29
 */
public class PrimitiveUtils {

    private static final Map<Class<?>, Class<?>> MAP_WRAPPER = new HashMap<>();

    static {
        MAP_WRAPPER.put(byte.class, Byte.class);
        MAP_WRAPPER.put(short.class, Short.class);
        MAP_WRAPPER.put(int.class, Integer.class);
        MAP_WRAPPER.put(long.class, Long.class);
        MAP_WRAPPER.put(float.class, Float.class);
        MAP_WRAPPER.put(double.class, Double.class);
        MAP_WRAPPER.put(boolean.class, Boolean.class);
        MAP_WRAPPER.put(char.class, Character.class);
    }

    /**
     * 获取对于的包装类型
     * @param primitive
     * @return
     */
    public static final Class<?> getWrapper(Class<?> primitive) {
        Class<?> ret = MAP_WRAPPER.get(primitive);
        return ret == null ? primitive : ret;
    }

}
